package com.coderman.controller.business;

import com.coderman.business.service.IObtainEmpService;
import com.coderman.business.service.IObtainEmpService;
import com.coderman.common.annotation.ControllerEndpoint;
import com.coderman.common.error.SystemException;
import com.coderman.common.model.student.ObtainEmp;
import com.coderman.common.model.system.Dept;
import com.coderman.common.response.ResponseBean;
import com.coderman.common.vo.system.PageVO;
import com.wuwenze.poi.ExcelKit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 就业管理
 *
 * @Author liwei
 * @Date 2023/1/8 14:11
 * @Version 1.0
 **/
@Api(tags = "系统模块-就业相关接口")
@Controller
@RequestMapping("/obtainEmp")
public class ObtainEmpController {


    @Autowired
    private IObtainEmpService obtainEmpService;

    /**
     * 就业列表
     *
     * @return
     */
    @ApiOperation(value = "就业列表", notes = "就业列表,根据就业名模糊查询")
    @GetMapping("/findObtainEmpList")
    @ResponseBody
    public ResponseBean<PageVO<ObtainEmp>> findObtainEmpList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(value = "pageSize") Integer pageSize,
                                                                 ObtainEmp obtainEmp) {
        PageVO<ObtainEmp> ObtainEmpsList = obtainEmpService.findobtainEmpList(pageNum, pageSize, obtainEmp);
        return ResponseBean.success(ObtainEmpsList);
    }

    /**
     * 所有就业
     *
     * @return
     */
    @ApiOperation(value = "所有就业")
    @GetMapping("/findAll")
    @ResponseBody
    public ResponseBean<List<ObtainEmp>> findAll() {
        List<ObtainEmp> obtainEmps = obtainEmpService.findAll();
        return ResponseBean.success(obtainEmps);
    }

//    /**
//     * 查找就业主任
//     *
//     * @return
//     */
//    @ApiOperation(value = "就业主任", notes = "查找就业主任,排除掉已经禁用的用户")
//    @GetMapping("/findDeanList")
//    @ResponseBody
//    public ResponseBean<List<DeanVO>> findDeanList() {
//        List<DeanVO> managerList = ObtainEmpService.findDeanList();
//        return ResponseBean.success(managerList);
//    }

    /**
     * 添加就业
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "添加就业失败", operation = "添加就业")
    @ApiOperation(value = "添加就业")
    @PostMapping("/add")
    @ResponseBody
    public ResponseBean add(@RequestBody @Validated ObtainEmp obtainEmp) {
        obtainEmpService.add(obtainEmp);
        return ResponseBean.success();
    }

    /**
     * 编辑就业
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "编辑就业")
    @RequiresPermissions({"ObtainEmp:edit"})
    @GetMapping("/edit/{id}")
    @ResponseBody
    public ResponseBean edit(@PathVariable Integer id) throws SystemException {
        ObtainEmp obtainEmp = obtainEmpService.edit(id);
        return ResponseBean.success(obtainEmp);
    }

    /**
     * 更新就业
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "更新就业失败", operation = "更新就业")
    @ApiOperation(value = "更新就业")
    @RequiresPermissions({"ObtainEmp:update"})
    @PostMapping("/update")
    @ResponseBody
    public ResponseBean update(@RequestBody @Validated ObtainEmp obtainEmp) throws SystemException {
        obtainEmpService.update(obtainEmp);
        return ResponseBean.success();
    }

    /**
     * 删除就业
     *
     * @param id
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "删除就业失败", operation = "删除就业")
    @ApiOperation(value = "删除就业")
    @RequiresPermissions({"ObtainEmp:delete"})
    @DeleteMapping("/delete/{id}")
    @ResponseBody
    public ResponseBean delete(@PathVariable Integer id) throws SystemException {
        obtainEmpService.deleteByPrimaryKey(id);
        return ResponseBean.success();
    }

    /**
     * 导出excel
     * @param response
     */
    @ApiOperation(value = "导出excel", notes = "导出所有就业的excel表格")
    @PostMapping("/excel")
    @RequiresPermissions("ObtainEmp:export")
    @ControllerEndpoint(exceptionMessage = "导出Excel失败",operation = "导出就业excel")
    public void export(HttpServletResponse response) {
        List<ObtainEmp> ObtainEmps = this.obtainEmpService.findAll();
        ExcelKit.$Export(Dept.class, response).downXlsx(ObtainEmps, false);
    }

}
